home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2005 October / PCWOCT05.iso / Software / FromTheMag / The GIMP 2.2.8 / gimp-2.2.8-i586-setup.exe / {app} / share / gimp / 2.0 / scripts / addborder.scm < prev    next >
Encoding:
GIMP Script-Fu Script  |  2005-06-30  |  6.0 KB  |  184 lines

  1. ; The GIMP -- an image manipulation program
  2. ; Copyright (C) 1995 Spencer Kimball and Peter Mattis
  3. ; This program is free software; you can redistribute it and/or modify
  4. ; it under the terms of the GNU General Public License as published by
  5. ; the Free Software Foundation; either version 2 of the License, or
  6. ; (at your option) any later version.
  7. ; This program is distributed in the hope that it will be useful,
  8. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  10. ; GNU General Public License for more details.
  11. ; You should have received a copy of the GNU General Public License
  12. ; along with this program; if not, write to the Free Software
  13. ; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  14. ;
  15. ; Copyright (C) 1997 Andy Thomas alt@picnic.demon.co.uk
  16. ;
  17. ; Version 0.2 10.6.97 Changed to new script-fu interface in 0.99.10
  18.  
  19. ; Delta the colour by the given amount. Check for boundary conditions
  20. ; If < 0 set to zero 
  21. ; If > 255 set to 255
  22. ; Return the new value
  23.  
  24. (define (deltacolour col delta)
  25.   (let* ((newcol (+ col delta)))
  26.     (if (< newcol 0) (set! newcol 0))
  27.     (if (> newcol 255) (set! newcol 255))
  28.     newcol)
  29.   )
  30.  
  31. (define (adjcolour col delta)
  32.   (mapcar (lambda (x) (deltacolour x delta)) col)
  33. )
  34.  
  35. (define (gen_top_array xsize ysize owidth oheight width height)
  36.   (let* ((n_array (cons-array 10 'double)))
  37.     (aset n_array 0 0 )
  38.     (aset n_array 1 0 )
  39.     (aset n_array 2 xsize)
  40.     (aset n_array 3 ysize)
  41.     (aset n_array 4 (+ xsize owidth))
  42.     (aset n_array 5 ysize)
  43.     (aset n_array 6 width)
  44.     (aset n_array 7 0 )
  45.     (aset n_array 8 0 )
  46.     (aset n_array 9 0 )
  47.     n_array)
  48. )
  49.  
  50. (define (gen_left_array xsize ysize owidth oheight width height)
  51.   (let* ((n_array (cons-array 10 'double)))
  52.     (aset n_array 0 0 )
  53.     (aset n_array 1 0 )
  54.     (aset n_array 2 xsize)
  55.     (aset n_array 3 ysize)
  56.     (aset n_array 4 xsize)
  57.     (aset n_array 5 (+ ysize oheight))
  58.     (aset n_array 6 0 )
  59.     (aset n_array 7 height )
  60.     (aset n_array 8 0 )
  61.     (aset n_array 9 0 )
  62.     n_array)
  63. )
  64.  
  65. (define (gen_right_array xsize ysize owidth oheight width height)
  66.   (let* ((n_array (cons-array 10 'double)))
  67.     (aset n_array 0 width )
  68.     (aset n_array 1 0 )
  69.     (aset n_array 2 (+ xsize owidth))
  70.     (aset n_array 3 ysize)
  71.     (aset n_array 4 (+ xsize owidth))
  72.     (aset n_array 5 (+ ysize oheight))
  73.     (aset n_array 6 width)
  74.     (aset n_array 7 height)
  75.     (aset n_array 8 width )
  76.     (aset n_array 9 0 )
  77.     n_array)
  78. )
  79.  
  80. (define (gen_bottom_array xsize ysize owidth oheight width height)
  81.   (let* ((n_array (cons-array 10 'double)))
  82.     (aset n_array 0 0 )
  83.     (aset n_array 1 height)
  84.     (aset n_array 2 xsize)
  85.     (aset n_array 3 (+ ysize oheight))
  86.     (aset n_array 4 (+ xsize owidth))
  87.     (aset n_array 5 (+ ysize oheight))
  88.     (aset n_array 6 width)
  89.     (aset n_array 7 height)
  90.     (aset n_array 8 0 )
  91.     (aset n_array 9 height)
  92.     n_array)
  93. )
  94.  
  95. (define (script-fu-addborder aimg adraw xsize ysize colour dvalue)
  96.   (let* ((img (car (gimp-drawable-get-image adraw)))
  97.          (owidth (car (gimp-image-width img)))
  98.          (oheight (car (gimp-image-height img)))
  99.          (width (+ owidth (* 2 xsize)))
  100.          (height (+ oheight (* 2 ysize)))
  101.          (layer (car (gimp-layer-new img
  102.                                      width height
  103.                                      (car (gimp-drawable-type-with-alpha adraw))
  104.                                      "Border-Layer" 100 NORMAL-MODE))))
  105.  
  106. ;Add this for debugging    (verbose 4)
  107.  
  108.     (gimp-context-push)
  109.  
  110.     (gimp-image-undo-group-start img)
  111.  
  112.     (gimp-image-resize img
  113.                        width
  114.                        height
  115.                        xsize
  116.                        ysize)
  117.  
  118.     (gimp-image-add-layer img layer 0)
  119.     (gimp-drawable-fill layer TRANSPARENT-FILL)
  120.  
  121.     (gimp-context-set-background (adjcolour colour dvalue))
  122.     (gimp-free-select img
  123.                       10
  124.                       (gen_top_array xsize ysize owidth oheight width height)
  125.                       CHANNEL-OP-REPLACE
  126.                       0
  127.                       0
  128.                       0.0)
  129.     (gimp-edit-fill layer BACKGROUND-FILL)
  130.     (gimp-context-set-background (adjcolour colour (/ dvalue 2)))
  131.     (gimp-free-select img
  132.                       10
  133.                       (gen_left_array xsize ysize owidth oheight width height)
  134.                       CHANNEL-OP-REPLACE
  135.                       0
  136.                       0
  137.                       0.0)
  138.     (gimp-edit-fill layer BACKGROUND-FILL)
  139.     (gimp-context-set-background (adjcolour colour (- 0 (/ dvalue 2))))
  140.     (gimp-free-select img
  141.                       10
  142.                       (gen_right_array xsize ysize owidth oheight width height)
  143.                       CHANNEL-OP-REPLACE
  144.                       0
  145.                       0
  146.                       0.0)
  147.  
  148.     (gimp-edit-fill layer BACKGROUND-FILL)
  149.     (gimp-context-set-background (adjcolour colour (- 0 dvalue)))
  150.     (gimp-free-select img
  151.                       10
  152.                       (gen_bottom_array xsize ysize owidth oheight width height)
  153.                       CHANNEL-OP-REPLACE
  154.                       0
  155.                       0
  156.                       0.0)
  157.  
  158.     (gimp-edit-fill layer BACKGROUND-FILL)
  159.     (gimp-selection-none img)
  160.     (gimp-image-undo-group-end img)
  161.     (gimp-displays-flush)
  162.  
  163.     (gimp-context-pop)))
  164.  
  165. (script-fu-register "script-fu-addborder"
  166.                     _"Add _Border..."
  167.                     "Add a border around an image"
  168.                     "Andy Thomas <alt@picnic.demon.co.uk>"
  169.                     "Andy Thomas"
  170.                     "6/10/97"
  171.                     "*"
  172.                     SF-IMAGE       "Input image"          0
  173.                     SF-DRAWABLE    "Input drawable"       0
  174.                     SF-ADJUSTMENT _"Border X size"        '(12 1 250 1 10 0 1)
  175.                     SF-ADJUSTMENT _"Border Y size"        '(12 1 250 1 10 0 1)
  176.                     SF-COLOR      _"Border color"         '(38 31 207)
  177.                     SF-ADJUSTMENT _"Delta value on color" '(25 1 255 1 10 0 1))
  178.  
  179. (script-fu-menu-register "script-fu-addborder"
  180.                          _"<Image>/Script-Fu/Decor")
  181.